/* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements.  See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License.  You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/


/*************************************************************************
 *\author: starlove
 *************************************************************************/
#ifndef __CC_PYTHON_IMPORT_O_SPRITEBATCHNODE_IMPL__
#define __CC_PYTHON_IMPORT_O_SPRITEBATCHNODE_IMPL__

#include "python_object_spritebatchnode.h"
#include "python_object_textureatlas.h"

NS_CCPY_BEGIN
	CCNODE_OBJECT_WRAPPER_IMPL(CCSpriteBatchNode, CPySpriteBatchNode)
	void __CCSpriteBatchNodeWrapper::g_insertQuadFromSprite(cocos2d::CCSprite *sprite, unsigned int index)
	{
		this->insertQuadFromSprite(sprite, index);
	}

    void __CCSpriteBatchNodeWrapper::g_updateQuadFromSprite(cocos2d::CCSprite *sprite, unsigned int index)
	{
		this->updateQuadFromSprite(sprite, index);
	}

    cocos2d::CCSpriteBatchNode *__CCSpriteBatchNodeWrapper::g_addSpriteWithoutQuad(cocos2d::CCSprite *child, unsigned int z, int aTag)
	{
		return this->addSpriteWithoutQuad(child, z, aTag);
	}

    cocos2d::CCTextureAtlas *__CCSpriteBatchNodeWrapper::get_m_pobTextureAtlas()
	{
		return this->m_pobTextureAtlas;
	}

    void __CCSpriteBatchNodeWrapper::set_m_pobTextureAtlas(cocos2d::CCTextureAtlas *v)
	{
		this->m_pobTextureAtlas = v;
	}
    cocos2d::ccBlendFunc __CCSpriteBatchNodeWrapper::get_m_blendFunc()
	{
		return this->m_blendFunc;
	}

	void __CCSpriteBatchNodeWrapper::set_m_blendFunc(cocos2d::ccBlendFunc v)
	{
		this->m_blendFunc = v;
	}

    cocos2d::CCArray* __CCSpriteBatchNodeWrapper::get_m_pobDescendants()
	{
		return this->m_pobDescendants;
	}

	void __CCSpriteBatchNodeWrapper::set_m_pobDescendants(cocos2d::CCArray* v)
	{
		this->m_pobDescendants = v;
	}


	PYCLASS_INIT_AND_BASE_2(CPySpriteBatchNode, CPyNode, CPyTextureProtocol, "CCSpriteBatchNode", "Python CCSprite Object");
	PYCLASS_BEGIN_METHOD_DEF(CPySpriteBatchNode)
		PYCLASS_ADD_METHOD(CPySpriteBatchNode, initWithTexture)
		PYCLASS_ADD_METHOD(CPySpriteBatchNode, initWithFile)
		PYCLASS_ADD_METHOD(CPySpriteBatchNode, increaseAtlasCapacity)
		PYCLASS_ADD_METHOD(CPySpriteBatchNode, removeChildAtIndex)
		PYCLASS_ADD_METHOD(CPySpriteBatchNode, insertChild)
		PYCLASS_ADD_METHOD(CPySpriteBatchNode, appendChild)
		PYCLASS_ADD_METHOD(CPySpriteBatchNode, removeSpriteFromAtlas)
		PYCLASS_ADD_METHOD(CPySpriteBatchNode, rebuildIndexInOrder)
		PYCLASS_ADD_METHOD(CPySpriteBatchNode, highestAtlasIndexInChild)
		PYCLASS_ADD_METHOD(CPySpriteBatchNode, lowestAtlasIndexInChild)
		PYCLASS_ADD_METHOD(CPySpriteBatchNode, atlasIndexForChild)
		PYCLASS_ADD_METHOD(CPySpriteBatchNode, reorderBatch)
		PYCLASS_ADD_METHOD(CPySpriteBatchNode, _insertQuadFromSprite)
		PYCLASS_ADD_METHOD(CPySpriteBatchNode, _updateQuadFromSprite)
		PYCLASS_ADD_METHOD(CPySpriteBatchNode, _addSpriteWithoutQuad)
	PYCLASS_END_METHOD_DEF(CPySpriteBatchNode)
	PYCLASS_BEGIN_GETSET_DEF(CPySpriteBatchNode)
		PYCLASS_ADD_GETSET(CPySpriteBatchNode, TextureAtlas)
		PYCLASS_ADD_GET(CPySpriteBatchNode, Descendants)
	PYCLASS_END_GETSET_DEF(CPySpriteBatchNode)
	PYCLASS_IMP_INTERFACE_NOINIT(CPySpriteBatchNode)
			
	int CPySpriteBatchNode::__init__(CPySpriteBatchNode *pySelf, PyObject *args, PyObject *kwds)
	{
		if( !args )
			return 0;
		static char* kwlist[] = {"fileImage", "texture", "capacity", NULL};
		char *filename = "";
		PyObject *py_texture = NULL;
		unsigned int cap = kDefaultSpriteBatchCapacity;
		if (!PyArg_ParseTupleAndKeywords(args,kwds,"|sOI",kwlist, &filename, &py_texture, &cap))
			return 0;
		cocos2d::CCSpriteBatchNode *spr = dynamic_cast<cocos2d::CCSpriteBatchNode *>(pySelf->getCCObject());
		if(!spr)
			return 0;
		if(filename && strlen(filename) > 0)
		{
			spr->initWithFile(filename, cap);
		}else if (py_texture && py_texture != Py_None)
		{
			if(!PyObject_TypeCheck(py_texture, CPyClassBase::GetTypeObject<CPyTexture2D>()))
				return 0;
			CPyTexture2D *texture = (CPyTexture2D *)py_texture;
			spr->initWithTexture((cocos2d::CCTexture2D *)texture->getCCObject(), cap);
		}
		return 0;
	}
	
	PYCLASS_METHOD_IMPL(CPySpriteBatchNode, initWithTexture)
	{
		PyObject *pytex = NULL;
		unsigned int cap = kDefaultSpriteBatchCapacity;
		if( !PyArg_ParseTuple(pyArgs, "OI", &pytex, &cap) )
			Py_RETURN_FALSE;		
		if(!PyObject_TypeCheck(pytex, CPyClassBase::GetTypeObject<CPyTexture2D>()))
			Py_RETURN_FALSE;
		CPyTexture2D *tex = (CPyTexture2D *)pytex;
		CC_METHOD_WRAPPER_GETER(__CCSpriteBatchNodeWrapper *, CPySpriteBatchNode, initWithTexture, bool, (cocos2d::CCTexture2D *)tex->getCCObject(), cap);
		Py_RETURN_BOOL(v);
	}

	PYCLASS_METHOD_IMPL(CPySpriteBatchNode, initWithFile)
	{
		char *fileImage = "";
		unsigned int cap = kDefaultSpriteBatchCapacity;
		if( !PyArg_ParseTuple(pyArgs, "sI", &fileImage, &cap) )
			Py_RETURN_FALSE;
		CC_METHOD_WRAPPER_GETER(__CCSpriteBatchNodeWrapper *, CPySpriteBatchNode, initWithFile, bool, fileImage, cap);
		Py_RETURN_BOOL(v);
	}

	PYCLASS_METHOD_IMPL(CPySpriteBatchNode, increaseAtlasCapacity)
	{
		CC_METHOD_WRAPPER_SETER(__CCSpriteBatchNodeWrapper *, CPySpriteBatchNode, increaseAtlasCapacity);
		Py_RETURN_NONE;
	}
	
	PYCLASS_METHOD_IMPL(CPySpriteBatchNode, removeChildAtIndex)
	{
		PyObject *pyb = NULL;
		int i = -1;
		if( !PyArg_ParseTuple(pyArgs, "IO", &i, &pyb) )
			Py_RETURN_NONE;
		if(i < 0)
			Py_RETURN_NONE;
		CC_METHOD_WRAPPER_SETER(__CCSpriteBatchNodeWrapper *, CPySpriteBatchNode, removeChildAtIndex, i, pyb != Py_False);
		Py_RETURN_NONE;
	}

	PYCLASS_METHOD_IMPL(CPySpriteBatchNode, insertChild)
	{
		PyObject *pyspr = NULL;
		int i = -1;
		if( !PyArg_ParseTuple(pyArgs, "OI", &pyspr, &i) )
			Py_RETURN_NONE;
		if(i < 0)
			Py_RETURN_NONE;
		if(!PyObject_TypeCheck(pyspr, CPyClassBase::GetTypeObject<CPySprite>()))
			Py_RETURN_NONE;
		CPySprite *spr = (CPySprite *)pyspr;
		CC_METHOD_WRAPPER_SETER(__CCSpriteBatchNodeWrapper *, CPySpriteBatchNode, insertChild, (cocos2d::CCSprite *)spr->getCCObject(), i);
		Py_RETURN_NONE;
	}

	PYCLASS_METHOD_IMPL(CPySpriteBatchNode, appendChild)
	{
		PyObject *pyspr = NULL;
		if( !PyArg_ParseTuple(pyArgs, "O", &pyspr) )
			Py_RETURN_NONE;
		if(!PyObject_TypeCheck(pyspr, CPyClassBase::GetTypeObject<CPySprite>()))
			Py_RETURN_NONE;
		CPySprite *spr = (CPySprite *)pyspr;
		CC_METHOD_WRAPPER_SETER(__CCSpriteBatchNodeWrapper *, CPySpriteBatchNode, appendChild, (cocos2d::CCSprite *)spr->getCCObject());
		Py_RETURN_NONE;
	}

	PYCLASS_METHOD_IMPL(CPySpriteBatchNode, removeSpriteFromAtlas)
	{
		PyObject *pyspr = NULL;
		if( !PyArg_ParseTuple(pyArgs, "O", &pyspr) )
			Py_RETURN_NONE;
		if(!PyObject_TypeCheck(pyspr, CPyClassBase::GetTypeObject<CPySprite>()))
			Py_RETURN_NONE;
		CPySprite *spr = (CPySprite *)pyspr;
		CC_METHOD_WRAPPER_SETER(__CCSpriteBatchNodeWrapper *, CPySpriteBatchNode, removeSpriteFromAtlas, (cocos2d::CCSprite *)spr->getCCObject());
		Py_RETURN_NONE;
	}

	PYCLASS_METHOD_IMPL(CPySpriteBatchNode, rebuildIndexInOrder)
	{
		PyObject *pyspr = NULL;
		int i = -1;
		if( !PyArg_ParseTuple(pyArgs, "OI", &pyspr, &i) )
			Py_RETURN_NONE;
		if(i < 0)
			Py_RETURN_NONE;
		if(!PyObject_TypeCheck(pyspr, CPyClassBase::GetTypeObject<CPySprite>()))
			Py_RETURN_NONE;
		CPySprite *spr = (CPySprite *)pyspr;
		CC_METHOD_WRAPPER_GETER(__CCSpriteBatchNodeWrapper *, CPySpriteBatchNode, rebuildIndexInOrder, unsigned int, (cocos2d::CCSprite *)spr->getCCObject(), i);
		return Py_BuildValue("I", v);
	}

	PYCLASS_METHOD_IMPL(CPySpriteBatchNode, highestAtlasIndexInChild)
	{
		PyObject *pyspr = NULL;
		if( !PyArg_ParseTuple(pyArgs, "O", &pyspr) )
			Py_RETURN_NONE;
		if(!PyObject_TypeCheck(pyspr, CPyClassBase::GetTypeObject<CPySprite>()))
			Py_RETURN_NONE;
		CPySprite *spr = (CPySprite *)pyspr;
		CC_METHOD_WRAPPER_GETER(__CCSpriteBatchNodeWrapper *, CPySpriteBatchNode, highestAtlasIndexInChild, unsigned int, (cocos2d::CCSprite *)spr->getCCObject());
		return Py_BuildValue("I", v);
	}

	PYCLASS_METHOD_IMPL(CPySpriteBatchNode, lowestAtlasIndexInChild)
	{
		PyObject *pyspr = NULL;
		if( !PyArg_ParseTuple(pyArgs, "O", &pyspr) )
			Py_RETURN_NONE;
		if(!PyObject_TypeCheck(pyspr, CPyClassBase::GetTypeObject<CPySprite>()))
			Py_RETURN_NONE;
		CPySprite *spr = (CPySprite *)pyspr;
		CC_METHOD_WRAPPER_GETER(__CCSpriteBatchNodeWrapper *, CPySpriteBatchNode, lowestAtlasIndexInChild, unsigned int, (cocos2d::CCSprite *)spr->getCCObject());
		return Py_BuildValue("I", v);
	}

	PYCLASS_METHOD_IMPL(CPySpriteBatchNode, atlasIndexForChild)
	{
		PyObject *pyspr = NULL;
		int i = 0;
		if( !PyArg_ParseTuple(pyArgs, "OI", &pyspr, &i) )
			Py_RETURN_NONE;
		if(!PyObject_TypeCheck(pyspr, CPyClassBase::GetTypeObject<CPySprite>()))
			Py_RETURN_NONE;
		CPySprite *spr = (CPySprite *)pyspr;
		CC_METHOD_WRAPPER_GETER(__CCSpriteBatchNodeWrapper *, CPySpriteBatchNode, atlasIndexForChild, unsigned int, (cocos2d::CCSprite *)spr->getCCObject(), i);
		return Py_BuildValue("I", v);
	}

	PYCLASS_METHOD_IMPL(CPySpriteBatchNode, reorderBatch)
	{
		PyObject *pyb = NULL;
		if( !PyArg_ParseTuple(pyArgs, "O", &pyb) )
			Py_RETURN_NONE;
		CC_METHOD_WRAPPER_SETER(__CCSpriteBatchNodeWrapper *, CPySpriteBatchNode, reorderBatch, pyb != Py_False);
		Py_RETURN_NONE;
	}

	PYCLASS_METHOD_IMPL(CPySpriteBatchNode, _insertQuadFromSprite)
	{
		PyObject *pyspr = NULL;
		int i = -1;
		if( !PyArg_ParseTuple(pyArgs, "OI", &pyspr, &i) )
			Py_RETURN_NONE;
		if(i < 0)
			Py_RETURN_NONE;
		if(!PyObject_TypeCheck(pyspr, CPyClassBase::GetTypeObject<CPySprite>()))
			Py_RETURN_NONE;
		CPySprite *spr = (CPySprite *)pyspr;
		CC_METHOD_WRAPPER_SETER(__CCSpriteBatchNodeWrapper *, CPySpriteBatchNode, g_insertQuadFromSprite, (cocos2d::CCSprite *)spr->getCCObject(), i);
		Py_RETURN_NONE;
	}

	PYCLASS_METHOD_IMPL(CPySpriteBatchNode, _updateQuadFromSprite)
	{
		PyObject *pyspr = NULL;
		int i = -1;
		if( !PyArg_ParseTuple(pyArgs, "OI", &pyspr, &i) )
			Py_RETURN_NONE;
		if(i < 0)
			Py_RETURN_NONE;
		if(!PyObject_TypeCheck(pyspr, CPyClassBase::GetTypeObject<CPySprite>()))
			Py_RETURN_NONE;
		CPySprite *spr = (CPySprite *)pyspr;
		CC_METHOD_WRAPPER_SETER(__CCSpriteBatchNodeWrapper *, CPySpriteBatchNode, g_updateQuadFromSprite, (cocos2d::CCSprite *)spr->getCCObject(), i);
		Py_RETURN_NONE;
	}
		
	PYCLASS_METHOD_IMPL(CPySpriteBatchNode, _addSpriteWithoutQuad)
	{
		PyObject *pyspr = NULL;
		int z = -1;
		int tag = 0;
		if( !PyArg_ParseTuple(pyArgs, "OI", &pyspr, &z, &tag) )
			Py_RETURN_NONE;
		if(z < 0)
			Py_RETURN_NONE;
		if(!PyObject_TypeCheck(pyspr, CPyClassBase::GetTypeObject<CPySprite>()))
			Py_RETURN_NONE;
		CPySprite *spr = (CPySprite *)pyspr;
		CC_METHOD_WRAPPER_SETER(__CCSpriteBatchNodeWrapper *, CPySpriteBatchNode, g_addSpriteWithoutQuad, (cocos2d::CCSprite *)spr->getCCObject(), z, tag);
		Py_RETURN_NONE;
	}
	
	PYCLASS_GET_IMPL(CPySpriteBatchNode, TextureAtlas)
	{
		CC_METHOD_WRAPPER_GETER(__CCSpriteBatchNodeWrapper *, CPySpriteBatchNode, getTextureAtlas, cocos2d::CCTextureAtlas *);
		CPyTextureAtlas *texatlas = CPyCCObject::create<CPyTextureAtlas>(v);
		return (PyObject *)texatlas;
	}

	PYCLASS_SET_IMPL(CPySpriteBatchNode, TextureAtlas)
	{
		if(!PyObject_TypeCheck(pyValue, CPyClassBase::GetTypeObject<CPyTextureAtlas>()))
			return 0;
		CPyTextureAtlas *texatlas = (CPyTextureAtlas *)pyValue;
		CC_METHOD_WRAPPER_SETER_RINT(__CCSpriteBatchNodeWrapper *, CPySpriteBatchNode, setTextureAtlas, (cocos2d::CCTextureAtlas *)texatlas->getCCObject());
		return 0;
	}

	PYCLASS_GET_IMPL(CPySpriteBatchNode, Descendants)
	{
		CC_METHOD_WRAPPER_GETER(__CCSpriteBatchNodeWrapper *, CPySpriteBatchNode, getDescendants, cocos2d::CCArray *);
		if(!v)
			Py_RETURN_NONE;
		unsigned int ac = v->count();
		PyObject *pylist = PyList_New(ac);
		for(unsigned int i = 0; i < ac; i ++)
		{
			if(!v->objectAtIndex(i))
				continue;
			PyList_Append(pylist, (PyObject *)CPyCCObject::create<CPyCCObject>(v->objectAtIndex(i)));
		}
		return PyList_AsTuple(pylist);
	}


NS_CCPY_END

#endif